#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "ResourceDemo.h"

#define BYTES_IN_MB 1048576
#define SLEEP_TIME_MS 1000

JNIEXPORT void JNICALL Java_ResourceDemo_eatMemory
  (JNIEnv* env, jobject obj, jint memoryLimit) {
  	int* ptr = NULL;
  	int size_t = memoryLimit * BYTES_IN_MB / sizeof(int);
  	ptr = (int*)malloc(memoryLimit * BYTES_IN_MB);
  	if (ptr == NULL) {
  		printf("%s\n", "Out of memory!");
  	}
  	for (int i = 0; i < size_t; i++) {
  		ptr[i] = 0;
  	}
  	// usleep(SLEEP_TIME_MS * 1000);
}
